<!-- 活动管理 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10" v-if="!pup">
      活动管理
    </p>
    <div>
      <dxtable :headBtn="headBtn" :dataJson="dataJson" :formJson="formJson" :portUrl="portUrl" :qx="qx" ref="databale"
        :hidebj="hidebj" :czFun="czFun"></dxtable>
    </div>
  </div>
  
  <n-modal v-model:show="xzcxwerr" preset="card" class="Stock-diagnosis">
  <template #header>
  <div>评论管理</div>
  </template>
  <div>
  <plgl type="5" :plid='plid'></plgl>
  </div>
  <template #action>
  <div class="tr">
  <n-button @click="xzcxwerr=false"> 关闭 </n-button>
  </div>
  </template>
  </n-modal>
</template>
<script lang='ts' setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost, qurl, hf, transferTimeYMD } from "../../util/index";
import { h, ref, reactive } from "vue";
import { NSwitch,NButton } from "naive-ui"
import dz from "./dz.vue";
import plgl from "./plgl.vue";
const props = defineProps({
  pup: { type: String },
});
const xzcxwerr= ref(false)
const plid = ref()
const qx = ref({})
const showModal = ref()
const videourl = ref()
let headBtn = [];
const zdList = ref()
const databale = ref();
const typeli = ref([])
const hidebj = ref(false)
const initeer = () => {
  databale.value.initDataExpose();
};
const emit = defineEmits(["callBack"]);
// 弹窗公用该列表
let dataJson = reactive([
  {
    title: "活动名称",
    key: "title",
    search: true, // 是否在搜索栏展示
    ellipsis: {
      tooltip: true
    }
  },
  {
    title: "关键词",
    key: "keyword",
    search: true, // 是否在搜索栏展示
    ellipsis: {
      tooltip: true
    },
    render(row) {
      try {
        row.keyword = row.keyword.split(",")
      } catch (e) {

      }
    try{
      if(!row.keyword[0]){
      row.keyword =[]
     }
    }catch(e){
      row.keyword =[]
    }

      return row.keyword
    }
  },
  {
    title: "活动链接",
    key: "url",
    width: 100,
    render(row) {
      return h("span", {
        class: "ls sz", onClick: () => {
          open(row.url)
        }
      }, "浏览")
    }
  },

  {
    title: "类别",
    key: "sort",
    width: 140,
    search: true, // 是否在搜索栏展示
    type: "select",
    options: [],
    render(row) {
      try {
        return typeli.value.filter(a => a.value == row.sort)[0].label
      } catch (e) {
        return "--"
      }
    }
  }, {
    title: "首页推荐",
    key: "recommendation",
    width: 100,
    search: true, // 是否在搜索栏展示
    type: "select",
    options: [
      {
        label: "全部",
        value: ""
      }, {
        label: "首页推荐",
        value: "2"
      }
    ],
    render(row) {
      return h(NSwitch, {
        value: row.recommendation == 2 ? true : false, async onUpdateValue(data) {
          databale.value.tableload(true)
          await dxget("xjyx/api/setAct", {
            id: row.id,
            recommendation: data ? 2 : 1
          })
          row.recommendation = data ? 2 : 1
          databale.value.tableload(false)
        }
      })
    }
  },
    {
    title: "点赞基数",
    key: "dianzan",
    width: 100,
    render(row) {
      return h(dz, {
        row,
        api:portUrl,
        keyName:"dianzan",
        onCallBack: () => {
          initeer();
        },
      })
      
    }
  }, {
    title: "收藏基数",
    key: "scjs",
    width: 100,
    render(row) {
      return h(dz, {
        row,
        api:portUrl,
        keyName:"scjs",
        onCallBack: () => {
          initeer();
        },
      })
      
    }
  },
  {
    title: "排序",
    width: 100,
    render(row) {
      row.databaseName = "xjyxmanagementActivities";
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: "140",
    type: "daterange",

  },
]);
let portUrl = "xjyx/xjyxmanagementActivities";

let formJson = reactive([

  {
    title: "活动名称",
    key: "title",
    type: "input",
    span: 24,
    required: true,
  },
  {
    title: "关键词",
    key: "keyword",
    type: "Tags",
    val: [],
    span: 24,
  },
  {
    title: "活动时间",
    key: "addTime",
    val: transferTimeYMD(new Date().getTime()),
    type: "date"
  },
  {
    title: "活动链接",
    key: "url",
    span: 24,
    type: "input",
    required: true,
  }, {
    title: "活动封面",
    key: "cover",
    type: "img",
    required: true,
  }, {
    title: "类别",
    key: "sort",
    required: true,
    type: "select",
    options: []
  }, 

])
const getcasetype = async () => {
  const { data }: any = await dxget("xjyx/api/sortList")
  formJson[5].options = data
  dataJson[3].options = [
    {
      label: "全部",
      value: ""
    },
    ...data
  ]
  typeli.value = data
  // ishjwoer.value = true
}
getcasetype()


let pupVal = props.pup;

if (pupVal) {
  hidebj.value = true
  dataJson = [
    {
      title: "活动名称",
      key: "title",
      search: true, // 是否在搜索栏展示
      ellipsis: {
        tooltip: true
      }
    },

    {
      title: "",
      key: "cover",
      width: 10,
      render(row) {
        return ''
      }
    },


    {
      title: "活动链接",
      key: "url",
      width: 100,
      render(row) {
        return h("span", {
          class: "ls sz", onClick: () => {
            open(row.url)
          }
        }, "浏览")
      }
    },

    {
      title: "类别",
      key: "sort",
      width: 100,
      search: true, // 是否在搜索栏展示
      type: "select",
      options: [],
      render(row) {
        try {
          return typeli.value.filter(a => a.value == row.sort)[0].label
        } catch (e) {
          return "--"
        }
      }
    },
  ];

  headBtn = [
    {
      name: "确认选择 ",
      async clickFun(row) {
        const arrList = row.join(",");
        emit("callBack", arrList);
      },
    },
  ];
  qx.value = {
    DeletePermissionID: "xjyxmanagementActivitiesdela", //删除
    EditPermissionIdentifier: "xjyxmanagementActivitiesbja", // 编辑
    NewPermissionIdentifier: "xjyxmanagementActivitiesxza", // 新建
    ViewPermissionID: "xjyxmanagementActivitiescka", // 查看
  };
} else {
  qx.value = {
    DeletePermissionID: "xjyxmanagementActivitiesdel", //删除
    EditPermissionIdentifier: "xjyxmanagementActivitiesbj", // 编辑
    NewPermissionIdentifier: "xjyxmanagementActivitiesxz", // 新建
    ViewPermissionID: "xjyxmanagementActivitiesck", // 查看
  };
}

const czFun = {
    fun: (row, loading) => {
        return [
            h(
                NButton,
                {
                    type: "info",
                    quaternary: true,
                    onClick: async (e) => {
                      xzcxwerr.value = true
                      plid.value = row.id
                    },
                },
                "评论管理"
            )

        ];
    },
};
</script>
  
  
  